package util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class MybatisUtil {
	public static SqlSession getSqlSession() {
		//获取连接
		SqlSession openSession=null;
		try {
			//配置文件的名字
			String resource = "mybatis-config.xml";
			//
			InputStream resourceAsStream = Resources.getResourceAsStream(resource);
			//
			SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
			openSession = sqlSessionFactory.openSession();
		} catch (IOException e) {
			e.printStackTrace();
		}
		//
		return openSession;
	}
}
